<?php
require_once ("../Utils/Utils.php");

class Zalozky {

	public function __construct($dataArray) {
		
		$this->renderInternalStyle();
		
		$p = $this->checkParam();
		
		if(!is_null($p)){
			$this->renderTop($dataArray);
			$this->renderContent($p,$dataArray);
		} else {
			$this->renderTop($dataArray);
		}
	}

	protected function checkParam() {
		$zal = Utils :: requestGet('zal');

		if (is_null($zal)) {
			return null;
		}

		return $zal;
	}

	protected function renderInternalStyle() {
		$out = "<style type='text/css'>
					<!--
	  .zalozky {
	    font-family: verdana;
	    font-size: 10px;
	    border: 1px black solid;
	  }
	//-->
	</style>";
	
		Utils::out($out);
	}

	/**
	 * vstup teto funcke by mel vypadat nejak takhle
	 * $array = array("Produkty"=>"products", "Uzivatele"=>"users");
	 * 
	 * cili klic (index) bude vyreslen a hodnota bude pouzita v parametru
	 */
	protected function renderTop($dataArray) {

		if (is_array($dataArray) && !is_null($dataArray)) {

			//$count = count($dataArray);

			Utils :: out("<table align='left' border='0' nowrap='nowrap' cellspacing='1' cellpadding='3'>");
			Utils :: out("<tr>");

			foreach ($dataArray as $key => $value) {
				Utils :: out("<td class='zalozky'> <a href='main.php?zal=$value'>$key</a></td>");
			}

			Utils :: out("</tr>");
			Utils :: out("</table>");

		}

	}
	
	protected function renderContent($concrete, $dataArray) {
		
		//dynamicky load tridy ?
//		$class = ucfirst($concrete)."Zalozka.php";
//		require_once($class);
//		
//		$trimed = rtrim($class,".php");
//		
//		$new = new $trimed;
//		
//		$new -> renderContent();

		$class = "ZalozkyRender.php";
		require_once($class);
		$trimed = rtrim($class,".php");
		$new = new $trimed;
		
		foreach ( $dataArray as $value ) {
       		if($value == $concrete) {
       			if(method_exists($new,"$concrete"."Render")){
       				call_user_method("$concrete"."Render",$new);	
       			} else {
       				Utils::out("<br><b>Render metoda neni pro zalozku implementovana..</b><br>");
       			}
       		
       		}
		}
		
	}

}
?>
